<template>
  <a-modal
    title="分析指标查询"
    :width="Fxwidth"
    :visible="visible"
    :maskClosable="false"
    :footer="null"
    @cancel="handleCancel"
  >
    <component
      :is="componentID"
      :projectItem="projectItem"
      :disableSubmit="disableSubmit"
      @addNumber="addNumber"
      @subNumber="subNumber"
      @getValue="getValue"
    />
    <a-row v-if="!disableSubmit">
      <a-col :span="8" :offset="8" style="text-align: center">
        <div class="btn_position">
          <a-button type="primary" @click="save">保存</a-button>
          <a-button @click="handleCancel" style="margin-left: 20px">取消</a-button>
        </div>
      </a-col>
    </a-row>
  </a-modal>
</template>

<script>
import AnalysisIndexrq from './AnalysisIndexrq'
import AnalysisIndexzd from './AnalysisIndexzd'
import AnalysisIndexby from './AnalysisIndexby'
import AnalysisIndexxj from './AnalysisIndexxj'
import AnalysisIndexcb from './AnalysisIndexcb'
export default {
  name: 'AnalysisIndex',
  components: { AnalysisIndexrq, AnalysisIndexzd, AnalysisIndexby, AnalysisIndexxj, AnalysisIndexcb },
  data() {
    return {
      componentID: '',
      visible: false,
      projectItem: undefined,
      disableSubmit: false,
      modelId: '',
      Fxwidth: 0,
      modeltype: {
        view_rqkhzb: {
          title: '任期考核指标',
          componentID: 'AnalysisIndexrq',
          Fxwidth: 980,
        },
        view_zdcwyczb: {
          title: '重大财务异常指标',
          componentID: 'AnalysisIndexzd',
          Fxwidth: 700,
        },
        view_cbzb: {
          title: '成本占比模型',
          componentID: 'AnalysisIndexcb',
          Fxwidth: 700,
        },
        view_cash_abnormal_model: {
          title: '现金（大额）异常模型',
          componentID: 'AnalysisIndexxj',
          Fxwidth: 500,
        },
        view_big_petty_cash_model: {
          title: '备用金（大额）异常模型',
          componentID: 'AnalysisIndexby',
          Fxwidth: 500,
        },
      },
    }
  },
  methods: {
    save() {
      let projectJson = JSON.stringify(this.projectItem)
      this.$emit('save', projectJson, this.modelId)
      this.visible = false
    },
    edit(projectItem, modelId, modelType) {
      this.componentID = this.modeltype[modelType].componentID
      this.Fxwidth = this.modeltype[modelType].Fxwidth
      this.modelId = modelId
      this.projectItem = projectItem
      this.visible = true
      this.disableSubmit = false
    },
    check(projectItem, modelId, modelType) {
      this.componentID = this.modeltype[modelType].componentID
      this.Fxwidth = this.modeltype[modelType].Fxwidth
      this.projectItem = projectItem
      this.visible = true
      this.disableSubmit = true
    },
    handleCancel() {
      this.visible = false
    },
    addNumber(mysite, type) {
      if (type) {
        let num = Number(this.projectItem[mysite]) + 0.01
        this.projectItem[mysite] = num > 1 ? 1 : num.toFixed(2)
      } else {
        this.projectItem[mysite]++
      }
    },
    subNumber(mysite, type) {
      if (type) {
        let num = Number(this.projectItem[mysite]) - 0.01
        this.projectItem[mysite] = num < 0 ? 0 : num.toFixed(2)
      } else {
        this.projectItem[mysite]--
      }
    },
    getValue(mysite, value) {
      this.projectItem[mysite] = value
    },
  },
}
</script>

<style lang="less" scoped>
</style>